package com.xi.mapper;

import com.xi.pojo.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface UserMapper {
    /*
     * 用户登录
     * */
    User getUsernameAndPassword(User user);

    /*
     * 用户分页查询
     * */
    List<User> list(UserQueryParam userQueryParam);

    /*
    * 根据id删除用户
    * */
    void deleteById(Integer id);

    /*
    * 获取总用户数
    * */
    Integer count();

    public List<Book> searchBookByParams(UserBookQueryParam userBookQueryParam);

    void addUser(User user);

    //@Select("SELECT * FROM user WHERE username = #{username}")
    User getUserByUsername(String username);


    List<Borrowable> searchBorrowBook();

    void addBorrow(Borrow borrow);

    int updateBookStock(@Param("bookId") Integer bookId, @Param("stock") int stock);

    Book getBookById(Integer bookId);

    List<Borrowable> searchBorrowBookByUserId(Integer userId);

    void updateBorrowStatus(Borrow borrow);

    /**
     * 根据用户ID和图书ID查询借阅记录
     */
    Borrow getBorrowRecord(@Param("userId") Integer userId, @Param("bookId") Integer bookId);

    void addReservation(Reservation reservation);

    List<Reservation> getReservationsByUserId(Integer userId);

    Reservation getExistingReservation(@Param("userId") Integer userId, @Param("bookId") Integer bookId);

    int deleteReservationById(Integer id);

    int updateUserInfo(User user);

    int updateUserInfo(@Param("oldUsername") String oldUsername,
                       @Param("newUsername") String newUsername,
                       @Param("realName") String realName,
                       @Param("phone") String phone);

    int changePassword(@Param("username") String username, @Param("newPassword") String newPassword);

    // 获取系统配置信息
    SystemConfig getSystemConfig();
}
